function clear_user_coupon_dialog_status() {
  console.log('销毁线上商家弹优惠券状态')
  wx.removeStorageSync('user_coupon_dialog_status')
}

//获取缓存数组
function get_user_coupon_dialog_list() {
  var list = wx.getStorageSync('user_coupon_dialog_status');
  return list;
}

//获取单个状态
function get_user_coupon_dialog_status(staffId) {
  var list = get_user_coupon_dialog_list();
  //不存在
  if (list == null || list === undefined || list === ''){
    return true;
  }
  
  var isExists = true;  //true:显示弹框, false: 不弹框
  for (var i = 0; i < list.length; i++) {
    //存在
    if (list[i].staffId == staffId) {
      isExists = list[i].state;
      break;
    }
  }
  return isExists;
}

//缓存领取状态
function set_user_coupon_dialog_status(staffId,state) { 
  var list = get_user_coupon_dialog_list();
  if (list==null|| list.length==0){
    list=[];
  }
  var item = { staffId: staffId, state: state };
  var isExists = false;
  for (var i = 0; i < list.length; i++) {
    //存在，修改
    if (list[i].staffId == staffId) {
      isExists = true;
      list[i] = item;
      break;
    }
  }
  //不存在，新增
  if(!isExists){
    list.push(item);  
  }    
  wx.setStorageSync('user_coupon_dialog_status', list)
}

module.exports={
  //获取线下商家优惠券弹出逻辑
  get_user_coupon_dialog_status:get_user_coupon_dialog_status,
  //设置线下商家优惠券弹出逻辑
  set_user_coupon_dialog_status: set_user_coupon_dialog_status,
  //清除线下商家优惠券弹出逻辑
  clear_user_coupon_dialog_status: clear_user_coupon_dialog_status
}